import './App.css'
import ReactECharts from 'echarts-for-react'
import { useEffect, useState } from 'react'
// import { useDispatch } from 'react-redux'
import axios from 'axios'
import './mock/test'
// import { getUserData } from './api/userInfo'
function App() {
  // const dispatch = useDispatch()
  useEffect(() => {
    async function getData() {
      const res = await axios.get('/test')
      console.log(res)
    }
    getData()
  }, [])
  const [state, setState] = useState({
    sales: [5, 20, 36, 10, 10, 20],
    stores: [15, 30, 56, 20, 20, 25],
  })
  const update = () => {
    setState((state) => ({
      sales: state.sales.map((item) => item + 1),
      stores: state.stores.map((item) => item - 1),
    }))
  }
  // 柱状图
  const getOption = (sales, stores) => {
    return {
      title: {
        text: 'ECharts 入门示例',
      },
      tooltip: {},
      legend: {
        data: ['销量', '库存'],
      },
      xAxis: {
        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'],
      },
      yAxis: {},
      series: [
        {
          name: '销量',
          type: 'bar',
          data: sales,
        },
        {
          name: '库存',
          type: 'bar',
          // data: [15, 30, 56, 20, 20, 25],
          data: stores,
        },
      ],
    }
  }
  return (
    <div className="App">
      <div>
        <button onClick={update}>更新数据</button>
      </div>
      <ReactECharts option={getOption(state.sales, state.stores)} />
    </div>
  )
}

export default App
